//
//  ZHWoDeViewController.m
//  ZhanHui
//
//  Created by 彭超 on 16/5/12.
//  Copyright © 2016年 彭超. All rights reserved.
//

#import "ZHWoDeViewController.h"

#import "ZHWeiDianViewController.h"
#import "ZHXinxiViewController.h"
#import "ZHMianFeiViewController.h"
#import "ZHLiuLanViewController.h"
#import "ZHPinLunViewController.h"
#import "ZHZiJinViewController.h"
#import "ZHShouCangViewController.h"
#import "ZHShouJuViewController.h"
#import "ZHXiaZaiViewController.h"

#import "UIButton+Extension.h"

@interface ZHWoDeViewController ()

@end

@implementation ZHWoDeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createButton];
    [self createNavigationItem];
}

-(void)createButton
{
    NSArray *array =@[@"我的微店",@"信息管理",@"免费发布",@"浏览记录",@"我的评论",@"我的资金",@"我的收藏",@"我的数据",@"APP下载"];
    for (int i=0; i<array.count; i++) {
        UIButton *button =[[UIButton alloc]initWithFrame:CGRectMake(i % 3 * self.view.frame.size.width/3, i/3 *(self.view.frame.size.height-113)/3 , self.view.frame.size.width/3, (self.view.frame.size.height-113)/3 )];
        button.tag =i;
        [button setImage:[UIImage imageNamed:[NSString  stringWithFormat:@"wode%d",i+1]] forState:UIControlStateNormal];
        [button setTitle:array[i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor colorWithRed: ( arc4random() % 256 / 256.0 ) green: ( arc4random() % 256 / 256.0 ) blue: ( arc4random() % 256 / 256.0 ) alpha:1] forState:UIControlStateNormal];
//        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        button.backgroundColor=[UIColor whiteColor];
        [button addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
        [button.layer setBorderWidth:0.5];
        [button.layer setCornerRadius:3.0];
        [self.view addSubview:button];
        [button centerImageAndTitle];
        
    }

}

-(void)createNavigationItem
{
    UIButton*bt=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
    [bt addTarget:self action:@selector(clickbutton:) forControlEvents:UIControlEventTouchUpInside];
    [bt setImage:[UIImage imageNamed:@"search"] forState:UIControlStateNormal];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:bt];
}

-(void)clickbutton:(UIButton*)button
{
    
}

-(void)clickBtn:(UIButton*)button
{
    NSInteger index = button.tag;
    if (index == 0) {
        ZHWeiDianViewController * weidian = [[ZHWeiDianViewController alloc]init];
        weidian.title = @"我的微店";
        [self.navigationController pushViewController:weidian animated:NO];
    }
    if (index == 1) {
        ZHXinxiViewController * weidian = [[ZHXinxiViewController alloc]init];
        weidian.title = @"信息管理";
        [self.navigationController pushViewController:weidian animated:NO];
    }
    if (index == 2) {
        ZHMianFeiViewController * weidian = [[ZHMianFeiViewController alloc]init];
        weidian.title = @"免费发布";
        [self.navigationController pushViewController:weidian animated:NO];
    }
    if (index == 3) {
        ZHLiuLanViewController * weidian = [[ZHLiuLanViewController alloc]init];
        weidian.title = @"浏览记录";
        [self.navigationController pushViewController:weidian animated:NO];
    }
    if (index == 4) {
        ZHPinLunViewController * weidian = [[ZHPinLunViewController alloc]init];
        weidian.title = @"我的评论";
        [self.navigationController pushViewController:weidian animated:NO];
    }
    if (index == 5) {
        ZHZiJinViewController * weidian = [[ZHZiJinViewController alloc]init];
        weidian.title = @"我的资金";
        [self.navigationController pushViewController:weidian animated:NO];
    }
    if (index == 6) {
        ZHShouCangViewController * weidian = [[ZHShouCangViewController alloc]init];
        weidian.title = @"我的收藏";
        [self.navigationController pushViewController:weidian animated:NO];
    }
    if (index == 7) {
        ZHShouJuViewController * weidian = [[ZHShouJuViewController alloc]init];
        weidian.title = @"我的数据";
        [self.navigationController pushViewController:weidian animated:NO];
    }
    if (index == 8) {
        ZHXiaZaiViewController * weidian = [[ZHXiaZaiViewController alloc]init];
        weidian.title = @"APP下载";
        [self.navigationController pushViewController:weidian animated:NO];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
